var StartMainLayer = cc.Layer.extend({
	lead:null,
	real:null,
	versions:null,
	ctor:function () {
		this._super();
		this.loadStartButton();
		this.loadStartButtonParticle();
		this.loadLightParticle();
		return true;
	},
	loadStartButton : function(){
		this.lead = new cc.MenuItemImage(
				"#home_lead1.png",
				"#home_lead2.png",
				this.eventMenuCallback,this);
		this.lead.setPosition(gg.width * 0.25, gg.height * 0.4);

		this.real =  new cc.MenuItemImage(
				"#home_real1.png",
				"#home_real2.png",
				this.eventMenuCallback,this);
		this.real.setPosition(gg.width * 0.75, gg.height * 0.4);

		this.versions=new cc.LabelTTF("V1.1", "Times new Roman", 16);
		this.versions.setFontFillColor(cc.color(0, 0, 0, 0));	
		this.versions.setPosition(gg.width*0.95, gg.height*0.034);

		var menu = new cc.Menu();
		this.addChild(menu);
		menu.setPosition(0, 0);
		menu.addChild(this.lead);
		menu.addChild(this.real);
		this.addChild(this.versions,1);
	},
	//加载特效
	loadLightParticle:function(){
		//cc.ParticleSystem粒子系统基类
		var light=new cc.ParticleSystem(res_start.particle_p);
		light.setPosition(-50,gg.height+50);
		this.addChild(light);
	},
	loadStartButtonParticle : function(){
		//粒子系统基类cc.ParticleSystem
		var lead_node = new cc.ParticleSystem(res_start.follow_p);
		this.addChild(lead_node);
		lead_node.setPosition(this.lead.x - this.lead.width / 2, this.lead.y - this.lead.height / 2);
		var action = this.getFollowAction(10, this.lead);
		lead_node.runAction(action);

		var real_node = new cc.ParticleSystem(res_start.follow_p);
		this.addChild(real_node);
		real_node.setPosition(this.real.x - this.real.width / 2, this.real.y - this.real.height / 2);
		var action = this.getFollowAction(10, this.real);
		real_node.runAction(action);
	},
	getFollowAction : function(stretch, node){
		var width = node.width;
		var height = node.height;
		//cc.bezierBy该动作按照贝塞尔曲线路径将目标移动到指定的位置。 相对于它的运动。
		var bezier1 = [cc.p(-stretch, 0), cc.p(-stretch, height), cc.p(0, height)];
		var bezierBy1 = cc.bezierBy(0.6, bezier1);
		var move1 = new cc.moveBy(0.7, cc.p(width, 0));

		var bezier2 = [cc.p(stretch, 0), cc.p(stretch, -height), cc.p(0, -height)];
		var bezierBy2 = cc.bezierBy(0.6, bezier2);
		var move2 = new cc.moveBy(0.7, cc.p(-width, 0));

		var action = cc.sequence(bezierBy1, move1, bezierBy2, move2).repeatForever();
		return action;
	},
	eventMenuCallback:function(pSend){
		switch(pSend){
		case this.lead:
			cc.log("进入引导模式");
			teach_type = TAG_LEAD;
			this.runPlay();
			break;
		case this.real:
			cc.log("进入实战模式");
			teach_type = TAG_REAL;
			this.runPlay();
			break;
		}
	},
	runPlay:function(){
		if(gg.play_load){
			$.runScene(new PlayScene());
		} else {
			if(this.tip == null){
				var fontDef = new cc.FontDefinition();
				fontDef.fontName = gg.fontName;
				fontDef.fontSize = gg.fontSize;
				fontDef.fillStyle = cc.color(0,0,0,0);
				this.tip = new cc.LabelTTF("加载中，请稍候再试",fontDef);
				this.tip.setPosition(gg.width * 0.5, gg.height * 0.5)
				this.addChild(this.tip);
			} else {
				this.tip.setVisible(true);
			}
			this.scheduleOnce(function(){
				this.tip.setVisible(false);	
			}.bind(this), 1.5);
		}
	}
});
